/*
 * @Author: 亚亚
 */
import Cookies from 'js-cookie'
const env = import.meta.env
const TokenKey = env.VITE_APP_IS_PA_MICRO === 'YES' ? 'Authorization' : 'Admin-Token'

export function getPlatformUser() {
  let userInfo = {}
  // if(process.env.VITE_APP_IS_PA_MICRO === 'YES') {
    if(typeof sessionStorage.getItem('userInfo') === 'string') {
      userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    }else {
      userInfo = sessionStorage.getItem('userInfo')
    }
    userInfo.userId = userInfo.currentContext.currentUser.userId
    userInfo.username = userInfo.name // 当前登录人姓名
    userInfo.mofDivId = userInfo.currentContext.currentUser.mofDivId
  // }else {
  //   userInfo = JSON.parse(Cookies.get('user') || '{}')
  // }
  return userInfo
}

export function getToken() {
  return Cookies.get(TokenKey) || sessionStorage.getItem('Authorization')
}